/**
 * 任务持久模块
 */
define('store/JobStore', ['WxCore','siteConfig','restTemplate'], function (wxCore,siteConfig,restTemplate) {

    const module= {
        storeName: 'JobStore',
        namespaced: true,
        state: {},
        mutations: {},
        actions: {
            getValidateRule () {
                return {
                    scheduleName: [
                        { required: true, message: '调度器名称不能为空', trigger: 'blur' }
                    ],
                    jobName: [
                        { required: true, message: '任务名称不能为空', trigger: 'blur' }
                    ],
                    jobGroup: [
                        { required: true, message: '任务分组不能为空', trigger: 'blur' }
                    ],
                    jobProviderBeanName: [
                        { required: true, message: '任务执行Bean名称不能为空', trigger: 'blur' }
                    ],
                    jobType: [
                        { required: true, message: '计划类型不能为空', trigger: 'blur' }
                    ],
                    startTime: [
                        { required: true, type: 'date', message: '开始时间不能为空', trigger: 'blur' }
                    ]
                }
            },
            loadList ({ state, commit }, { pageIndex, pageSize }) {
                return restTemplate.request({
                    baseURL:siteConfig.service.jobUrl,
                    url: '/WxJob/list',
                    params: {
                        pageIndex,
                        pageSize
                    },
                    method: 'get'
                })
            },
            save ({ state, commit }, vo) {
                const requestUrl = (vo.jobId && vo.jobId !== '') ? '/WxJob/update' : '/WxJob/add'
                return restTemplate.request({
                    baseURL:siteConfig.service.jobUrl,
                    url: requestUrl,
                    method: 'post',
                    data: vo
                })
            },
            delete ({ state, commit }, { jobId }) {
                return restTemplate.request({
                    baseURL:siteConfig.service.jobUrl,
                    url: '/WxJob/delete',
                    method: 'post',
                    params: {id: jobId},
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    }
                })
            },
            stop ({ state, commit }, { jobId }) {
                return restTemplate.request({
                    baseURL:siteConfig.service.jobUrl,
                    url: '/WxJob/stop',
                    method: 'post',
                    params: {id: jobId},
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    }
                })
            },
            restart ({ state, commit }, { jobId }) {
                return restTemplate.request({
                    baseURL:siteConfig.service.jobUrl,
                    url: '/WxJob/restart',
                    method: 'post',
                    params: {id: jobId},
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    }
                })
            },
            pause ({ state, commit }, { jobId }) {
                return restTemplate.request({
                    baseURL:siteConfig.service.jobUrl,
                    url: '/WxJob/pause',
                    method: 'post',
                    params: {id: jobId},
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    }
                })
            },
            resume ({ state, commit }, { jobId }) {
                return restTemplate.request({
                    baseURL:siteConfig.service.jobUrl,
                    url: '/WxJob/resume',
                    method: 'post',
                    params: {id: jobId},
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    }
                })
            }
        }
    };
    return module;
})